package cn.tedu.tmall.front.mall.controller;

import cn.tedu.tmall.common.pojo.po.CurrentUser;
import cn.tedu.tmall.common.pojo.vo.PageData;
import cn.tedu.tmall.common.web.JsonResult;
import cn.tedu.tmall.front.mall.pojo.param.OrderCreateParam;
import cn.tedu.tmall.front.mall.pojo.vo.OrderVO;
import cn.tedu.tmall.front.mall.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "订单模块")
@Slf4j
@Validated
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private IOrderService orderService;

    /**
     * 创建订单
     * @param user 当前登录用户
     * @param orderCreateParam 创建订单参数
     * @return 创建订单结果
     */
    @ApiOperation("创建订单")
    @PostMapping("/create")
    public JsonResult createOrder(@ApiIgnore @AuthenticationPrincipal CurrentUser user,
                                  @RequestBody OrderCreateParam orderCreateParam) {
        orderService.createOrder(user, orderCreateParam);
        return JsonResult.ok();
    }

    /**
     * 订单列表
     * @param user 当前登录用户
     * @return 订单列表 List<OrderVO>
     */
    @ApiOperation("订单列表")
    @GetMapping("/list")
    public JsonResult list(@ApiIgnore @AuthenticationPrincipal CurrentUser user,
                           @RequestParam Integer pageNum,
                           @RequestParam Integer pageSize) {
        PageData<OrderVO> orders = orderService.list(user, pageNum, pageSize);
        return JsonResult.ok(orders);
    }

    /**
     * 订单详情
     * @param user 登录用户
     * @param orderId 订单id
     * @return OrderDetailVO
     */
    @ApiOperation("订单详情")
    @GetMapping("/detail")
    public JsonResult detail(@ApiIgnore @AuthenticationPrincipal CurrentUser user,
                             @RequestParam Long orderId) {
        return JsonResult.ok();
    }

}
